{extend name="base" /}
{block name="content"}
<div class="g-index">
    <div class="m-index-header">
        <div class="m-container-fluid clearfix">
            <h1>{$site_info.site_name}</h1>
            <ul class="m-main-nav fl">
                {foreach name="menus" key="key" item="menu"}
                <li class="{if condition="$menu['id'] neq 2"}m-nav-menu{else/}m-drop-down{/if}{if condition='$key eq 0'} item-act{/if}"><a href="javascript:;">{$menu.name}{if condition="$menu['id'] eq 2"}<i class="icon-angle-down"></i>{/if}</a>
                    {if condition="$menu['id'] eq 2"}
                    <ul class="m-child">
                        {foreach name="menu['child']" key="k" item="second"}
                        <li class="m-nav-menu{if condition="count($menu['child']) eq ($k - 1)"} m-last{/if}"><a href="javascript:;">{$second.name}</a></li>
                        {/foreach}
                    </ul>
                    {/if}
                </li>
                {/foreach}
            </ul>
            <ul class="m-side-nav fr">
                <li><p>您好，管理员 {:session('username', '', session_prefix())}</p></li>
                <li><a href="/manage" title="网站首页" target="_blank"><i class="icon-home"></i></a></li>
				<li><a href="javascript:;" title="修改密码" id="j_edit" ><i class="icon-edit"></i>修改密码</a></li>
                <li><a href="javascript:;" title="退出登录" id="j_quit"><i class="icon-signout"></i>退出</a></li>
            </ul>
        </div>
    </div>
    <div class="m-index-aside">
        {foreach name="menus" key="key" item="menu"}
        {if condition="$menu.id eq 2"}
        {foreach name="menu['child']" item="second"}
        <div class="m-aside-nav{if condition='$key eq 0'} dn{/if}">
            {if condition="$second['child']"}
            {foreach name="second['child']" item="third"}
            <dl>
                <dt><i class="icon {$third.icon ?: 'icon-circle-blank'}"></i>{$third.name}<i class="icon-angle icon-angle-down"></i></dt>
                <dd>
                    <ul>
                        {foreach name="third['child']" item="four"}
                        <li><a href="{$four.url}" target="main">{$four.name}</a></li>
                        {/foreach}
                    </ul>
                </dd>
            </dl>
            {/foreach}
            {else/}
            <div class="m-column-trees">
                {if condition="$trees"}
                <ul class="columns-tree">{:html_entity_decode($trees)}</ul>
                {else/}
                <p>暂无相关栏目</p>
                {/if}
            </div>
            {/if}
        </div>
        {/foreach}
        {else/}
        <div class="m-aside-nav{if condition='$key eq 0'} dn{/if}">
            {if condition="$menu['child']"}
            {foreach name="menu['child']" item="second"}
            <dl>
                <dt><i class="icon {$second.icon ?: 'icon-circle-blank'}"></i>{$second.name}<i class="icon-angle icon-angle-down"></i></dt>
                <dd>
                    <ul>
                        {foreach name="second['child']" item="third"}
                        <li><a href="{$third.url}" target="main">{$third.name}</a></li>
                        {/foreach}
                    </ul>
                </dd>
            </dl>
            {/foreach}
            {else/}
            <dl>{$menu.name}</dl>
            {/if}
        </div>
        {/if}
        {/foreach}
    </div>
    <div class="m-animate-aside"><a href="javascript:;" class="animate-btn" onclick="animate_aside(this)"></a></div>
    <div class="m-index-main"><iframe src="{:url('welcome')}" name="main" id="main_frame" scrolling="yes" frameborder="0"></iframe></div>
</div>
{/block}
{block name="extrajs"}
<script>
    $(function(){
        layui.use('layer', function(){
            $('#j_quit').on('click', function(){
                layer.open({
                    title: '提示信息',
                    btn: ['确定', '取消'],
                    content: '您确定要退出登录吗？',
                    icon: 3,
                    yes: function(index){
                        // 确定
                        $.post('/quit', {}, function(ret){
                            if (ret.status == 0) {
                                layer.close(index);
                                window.location.href = '/manage';
                            }
                        }, 'json');
                    },
                    btn2: function(index){
                        // 取消
                    }
                });
            });
        });
        
        $('.m-drop-down').hover(function(){
            $(this).find('ul').show();
        }, function(){
            $(this).find('ul').hide();
        });
        
        $('.m-aside-nav dd li').click(function(){
            $('.m-aside-nav dd li').removeClass('m-item-act');
            $(this).addClass('m-item-act');
        });
        
        $('.u-cate').click(function(){
            var $ul = $(this).parent().find('ul:eq(0)');
            if ($ul.is(':hidden')) {
                $(this).find('.icon-tree-control').removeClass('ico-tree-plus').addClass('ico-tree-minus');
                $(this).find('.ico-folder').removeClass('ico-tree-folder-close').addClass('ico-tree-folder-open');
                $ul.slideDown(150);
            } else {
                $(this).find('.icon-tree-control').removeClass('ico-tree-minus').addClass('ico-tree-plus');
                $(this).find('.ico-folder').removeClass('ico-tree-folder-open').addClass('ico-tree-folder-close');
                $ul.slideUp(150);
            }
        });
        $('#j_edit').on('click',function(){

            var edit_html="<div class=\"layui-form\" lay-filter=\"layuiadmin-form-useradmin\" id=\"layuiadmin-form-useradmin\" style=\"padding: 20px 0 0 0;\">\n" +


                "    <div class=\"layui-form-item\">\n" +


                "      <label class=\"layui-form-label\">旧密码</label>\n" +


                "      <div class=\"layui-input-inline\">\n" +


                "        <input type=\"password\" name=\"old_pass\" lay-verify=\"required\" placeholder=\"请输入旧密码\" autocomplete=\"off\" class=\"layui-input\">\n" +


                "      </div>\n" +


                "    </div>\n" +


                "    <div class=\"layui-form-item\">\n" +


                "      <label class=\"layui-form-label\">新密码</label>\n" +


                "      <div class=\"layui-input-inline\">\n" +


                "        <input type=\"password\" name=\"new_pass\" lay-verify=\"required\" placeholder=\"请输新密码\" autocomplete=\"off\" class=\"layui-input\">\n" +


                "      </div>\n" +


                "    </div>\n" +


                "    <div class=\"layui-form-item\">\n" +


                "      <label class=\"layui-form-label\">确认密码</label>\n" +


                "      <div class=\"layui-input-inline\">\n" +


                "        <input type=\"password\" name=\"confirm_pass\" lay-verify=\"required\" placeholder=\"请输确认密码\" autocomplete=\"off\" class=\"layui-input\">\n" +


                "      </div>\n" +


                "    </div>\n" +


                "  </div>\n" +


                "<div class=\"layui-layer-btn layui-layer-btn-\" style=\"text-align: center;\">  <button id=\"j_edit_pass\" class=\"u-btn\">确定提交</button></div></div>" +


                "<span class=\"layui-layer-setwin\"><a class=\"layui-layer-ico layui-layer-close layui-layer-close1\" href=\"javascript:;\"></a></span>";


            layer.open({


                type: 1,


                title:'修改密码',


                shadeClose: true, //点击遮罩关闭


                area: ['400px', '350px'], //宽高


                content: edit_html


            });


        })



        //修改密码


        $("body").on("click","#j_edit_pass",function(){


            var old_pass=$("input[name='old_pass']").val();


            var new_pass=$("input[name='new_pass']").val();


            var confirm_pass=$("input[name='confirm_pass']").val();


            if(old_pass==='' || old_pass===null || old_pass===undefined){

                layer.msg('请输入旧密码不能空！');

                return false;

            }

            if(new_pass==='' || new_pass===null || new_pass===undefined){

                layer.msg('请输入新密码不能空！');

                return false;

            }

            if(confirm_pass==='' || confirm_pass===null || confirm_pass===undefined){

                layer.msg('请输入确认密码不能空！');

                return false;

            }

            if(new_pass !==confirm_pass){

                layer.msg('新密码与确认不相同！');

                return false;

            }

            $.post('/manage/users/editpass',{

                old_pass:old_pass,

                password:new_pass,

                password_confirm:confirm_pass

            },function(res){

                console.log(res)

                if(res.code===1){

                    layer.msg(res.msg);

                    setTimeout(function(){


                        layer.closeAll();


                        $.post('/quit', {}, function(ret){


                            console.log(ret)


                            if (ret.status == 0) {


                                window.location.href = '/manage';


                            }


                        }, 'json');


                    },1000)


                }else{


                    layer.msg(res.msg);


                }


            })


        });
    });
    
    function jsSwitch(ele, divId, divName, divCount)
    {
        for (var i = 0; i < divCount; i++) {
            $('#' + divName + i).hide();
        }
        $('.m-main-nav li').removeClass('item-act');
        $(ele).parent().addClass('item-act');
        $('#' + divName + divId).show();
    }
</script>
{/block}